﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Codebricks.Db.Attributes;
using Codebricks.Db.Interface;
using KBVault.DAL.Repository;

namespace KBVault.DAL.Entities
{
    [MySqlTable("articles")]
    public class Article:IMysqlTable
    {
        [MySqlPrimaryKey(true)]
        [MySqlField("Id")]
        public int Id { get; set; }

        [MySqlField("Title")]
        public string Title { get; set; }

        [MySqlField("Content")]
        public string Content { get; set; }

        [MySqlField("Category_Id")]
        public int CategoryId { get; set; }

        [MySqlField("Meta_Description")]
        public string MetaDescription { get; set; }

        [MySqlField("Views")]
        public int ViewCount { get; set; }

        [MySqlField("Likes")]
        public int LikeCount { get; set; }

        [MySqlField("Created")]
        public DateTime Created { get; set; }

        [MySqlField("Edited")]
        [MySqlIgnoreOnUpdate]
        public DateTime Edited { get; set; }

        [MySqlField("Is_Draft")]
        public int IsDraft { get; set; }

        [MySqlField("Publish_Start_Date")]
        public DateTime PublishStartDate { get; set; }

        [MySqlField("Publish_End_Date")]
        public DateTime PublishEndDate { get; set; }

        public Category Category { 
            get {
                return CategoryRepository.Get(CategoryId);
            } 
        }

        public List<Tag> Tags = new List<Tag>();

        public List<Attachment> Attachments
        {
            get
            {
                return AttachmentRepository.GetArticleAttachments(Id);
            }
        }

        public string ShortTitle
        {
            get
            {
                return Title.Length > 30 ? Title.Substring(0, 30) : Title;
            }
        }
    }
}
